////////////////////////////////////////////////////////////////////////////////////////////////////
// unshadowed, unskinned phong for up to N positional/directional light sources
////////////////////////////////////////////////////////////////////////////////////////////////////

const int num_lights = 3;

attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec2 TexCoord;

uniform mat4 mvp;
uniform vec4 lp_obj[num_lights];	// light position in object space; w = 0: directional
uniform vec4 vp_obj;				// viewer position in object space; w = 0: orthographic

varying vec3 n_obj_i;				// surface normal vector in object space
varying vec3 l_obj_i[num_lights];	// light-source vector in object space, one per light
varying vec3 h_obj_i[num_lights];	// half-direction vector in object space, one per light
varying vec2 tc_i;					// pre-baked texture mapping coordinates

void main()
{
	gl_Position = mvp * vec4(Vertex, 1.0);

	n_obj_i = Normal;

	for (int i = 0; i < num_lights; ++i)
	{
		vec4 lp_obj = lp_obj[i];

		vec3 l_obj = normalize(lp_obj.xyz - Vertex.xyz * lp_obj.w);
		vec3 v_obj = normalize(vp_obj.xyz - Vertex.xyz * vp_obj.w);

		l_obj_i[i] = l_obj;
		h_obj_i[i] = l_obj + v_obj;
	}

	tc_i = TexCoord;
}
